var app = getApp()
Page({
  data: {
    showLoading: true,
    noMoretip: false,
    page: 0
  },
  onLoad: function (e) {
    var that = this;
    if (e && e.title) {
      app.setNavtitle(e.title);
    } else {
      app.setNavtitle('帮助中心');
    }
    that.requestHelplist();
  },
  onShow:function(){
    var that = this;
  },
  requestHelplist:function(){
    var that = this;
    var data = {};
    var page = that.data.page;
    data.map = 'applet_help_center_list';
    data.page = page;
    wx.request({
      url: app.globalData.requestUrl,
      data: data,
      success: function (res) {
        if (res.data.ec == 200) {
          console.log(res.data.data);
          var allArr = [];
          var initArr = that.data.helpList;
          var curArr = res.data.data.list;
          var lastPageLength = curArr.length;
          if (page > 0) {
            allArr = initArr.concat(curArr);
          } else {
            allArr = res.data.data.list;
          }
          that.setData({
            helpList: allArr,
            mobile: res.data.data.info.shopPhone
          })
          if (lastPageLength < 10) {
            that.setData({
              noMoretip: true,
              showLoading: false
            });
          }
          console.log(that.data.helpList);
        } else {
          console.log(res.data)
          if (page <= 0) {
            that.setData({
              helpList: [],
              noMoretip: false,
              showLoading: false
            })
          } else {
            that.setData({
              noMoretip: true,
              showLoading: false
            });
          }
        }
      },
      complete: function () {
        wx.stopPullDownRefresh();
      }
    });
  },
  makeCall: function () {
    var mobile = this.data.mobile;
    app.makeCallphone(mobile);
  },
  openHelpDetail:function(e){
    var id = e.currentTarget.dataset.id;
    console.log(id);
    wx.navigateTo({
      url: '/subpages0/helpDetail/helpDetail?id='+id
    })
  }
})